<?php

namespace App\Console\Commands;

use App\Util\Help;
use Carbon\Carbon;
use EasyWeChat\Kernel\Exceptions\RuntimeException;
use EasyWeChat\Kernel\Support\AesGcm;
use EasyWeChat\Pay\Application;
use Illuminate\Console\Command;

class Test extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {
//        $attributes = json_decode('{"id":"1b888de4-9234-54da-9bdc-f6ff58884af2","create_time":"2024-06-21T16:37:16+08:00","resource_type":"encrypt-resource","event_type":"TRANSACTION.SUCCESS","summary":"支付成功","resource":{"original_type":"transaction","algorithm":"AEAD_AES_256_GCM","ciphertext":"obKksKmrl+qw8B+MOf51K8EN1XjBy2R8RC+O4xJMhKPTG++/Q8Cddm23fUz5bQQaUAPRW9nVSdRa5z1n4TNUkWjhocZvk0s0MbovU3RIleZgi85TI8XIZZCWVNNgmTo2G3FgVtPckdH0DtWwrwTUNvXkzbT4LNagwxQhZ8ogLB+sqS6yEfNPTiMs3m0H6GFrLABVPW5qZQm6KqE1VTSHTngh6o2hxY2OgdtEZDIqltXo4e7wEvw8ua7bgz3B103SUmx7tzVdFZae81fbHaBDJplkvCPWfeSvq0XgsGJf3OKnHCQYmU0vklaLb5ekhiaJdqUjJAXqOV1CGNVnuwQv+oicDOOyPwHx/STSzzsLiyJG9adccGhDvTc2vQ051mm2u2YldxVpWLxooH6UgrE0dUcE5hTQiJGzlJKTCaFhFNnjxIv3Ebxvh3gyxLqolsilSL6DILi5WDFRw2UxyqOLvg4L2zz+7V9ZH9sxs+GBoMc7o4g21smeF4G+b5FNQSipOML4V1osEW/oarzGkTYsUc5jwIovcLpqqM2AqA9x0HaIw0BpzzYRxTxh9kXQygyR/BdhPsA=","associated_data":"transaction","nonce":"l2L1ig5YaZgO"}}', true);
//
//        $attributes = json_decode(
//            AesGcm::decrypt(
//                $attributes['resource']['ciphertext'],
//                '1Ch3q5wD3zXaBVkBWcOASqO9gd5bQODw',
//                $attributes['resource']['nonce'],
//                $attributes['resource']['associated_data'],
//            ),
//            true
//        );
//        dd($attributes);
//        $config = config('wechatpay');
//        $app = new Application($config);
//        $response = $app->getClient()->postJson("v3/pay/transactions/jsapi", [
//            "mchid" => $config['mch_id'], // <---- 请修改为您的商户号
//            "out_trade_no" => "202406032031344YNGyT",
//            "appid" => "wx85953554e10b0123", // <---- 请修改为服务号的 appid
//            "description" => "测试检测",
//            "notify_url" => "https://wechat.lychix.com/api/v1/mini/payment_notify",
//            "amount" => [
//                "total" => 1,
//                "currency" => "CNY"
//            ],
//            "payer" => [
//                "openid" => "og5wT7TSUmJRFcG_Q8N4LrOq33pc" // <---- 请修改为服务号下单用户的 openid
//            ]
//        ]);
//        $response = $app->getClient()->postJson('v3/pay/transactions/native', [
//            'mchid' => (string)$app->getMerchant()->getMerchantId(),
//            'out_trade_no' => '202406032031344YNGyT',
//            'appid' => 'wx85953554e10b0123',
//            'description' => '测试检测',
//            'notify_url' => 'https://wechat.lychix.com/api/v1/mini/payment_notify',
//            'amount' => [
//                'total' => 1,
//                'currency' => 'CNY',
//            ]
//        ]);
//        dd($response->toArray(false));
    }
}
